<template>
  <div class="home-group">
    <div class="home-group-header">
      <h3 class="home-group-title">大家都在领</h3>
      <div class="home-group-tip">
        <span>{{
          parseInt(groupList?.total_quan_over?.now_num / 1000) +
          "," +
          (groupList?.total_quan_over?.now_num % 1000)
        }}</span>
        今日实时领券
      </div>
    </div>
    <div class="home-group-goods">
      <div
        class="home-group-good"
        v-for="item in groupList.list"
        :key="item.id"
      >
        <div class="home-group-img">
          <img :src="item.pic" alt="图片加载失败" />
        </div>
        <div class="home-group-price">¥ {{ item.price }}</div>
        <div class="home-group-scroll">
          <span
            >已领{{
              item.couponOver > 10000
                ? parseInt(item.couponOver / 1000) / 10 + "w"
                : item.couponOver
            }}张券</span
          >
          <div
            class="home-group-progress"
            :style="{ width: (item.couponOver / item.couponNum) * 100 + '%' }"
          ></div>
        </div>
        <div class="home-group-get">
          <span v-if="(item.couponOver / item.couponNum) * 100 <= 60"
            >火热领券中</span
          >
          <span
            v-if="
              (item.couponOver / item.couponNum) * 100 > 60 &&
              (item.couponOver / item.couponNum) * 100 < 90
            "
            >急速递减中</span
          >
          <span v-if="(item.couponOver / item.couponNum) * 100 >= 90"
            >即将领完</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, onMounted } from "vue";
import { useStore } from "vuex";

export default defineComponent({
  setup() {
    const store = useStore();
    const groupList = computed(() => store.state.home.groupList);
    onMounted(() =>
      store.dispatch({
        type: "home/getGroupList",
        data: {
          entityId: 4,
          modelId: 28996,
          proModelId: 16,
          source: 3,
          version: "v1",
          tuserId: 771131,
          isWechat: 0,
        },
      })
    );
    return {
      groupList,
    };
  },
});
</script>

<style lang="stylus" scoped>
.home-group {
  margin-top: 0.1rem;
  padding: 0.1rem;
  font-size: 0.12rem;
  background: white;
  border-radius: 0.05rem;

  .home-group-header {
    margin-bottom: 0.2rem;
    display: flex;
    justify-content: space-between;
    padding-right: 0.1rem;

    .home-group-title {
      margin: 0;
      font-weight: normal;
      font-size: 0.15rem;
    }

    .home-group-tip {
      span {
        font-size: 0.14rem;
        color: #f9635d;
        line-height: 0.2rem;
        margin-right: 0.05rem;
      }
    }
  }

  .home-group-goods {
    display: flex;
    overflow-x: auto;

    &::-webkit-scrollbar {
      display: none;
    }

    .home-group-good {
      .home-group-img {
        width: 1.05rem;
        height: 1.05rem;
        border-radius: 0.05rem;
        overflow: hidden;
        margin: 0 0.05rem;

        img {
          width: 100%;
          height: 100%;
        }
      }

      .home-group-price {
        font-size: 0.16rem;
        color: #ff3b32;
      }

      .home-group-scroll {
        position: relative;
        width: 105px;
        height: 12px;
        background: linear-gradient(180deg, #ffd7d0 0, #ffc0c0 100%);
        border-radius: 6px;
        margin: 6px 0 3px;
        overflow: hidden;

        span {
          display: block;
          position: absolute;
          width: 100%;
          height: 100%;
          z-index: 10;
          left: 0;
          top: 0;
          font-size: 9px;
          font-weight: 400;
          color: #fff;
          line-height: 12px;
          text-align: center;
        }

        .home-group-progress {
          width: 20%;
          height: 12px;
          border-radius: 6px;
          position: absolute;
          top: 0;
          left: 0;
          overflow: hidden;
          line-height: 12px;
          text-align: center;
          z-index: 5;
          background: linear-gradient(90deg, #ff5152 0, #fe3738 100%);
        }
      }

      .home-group-get {
        span {
          color: #888888;
        }
      }
    }
  }
}
</style>
